package com.v2.k42;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

@Component
public class TestInstantiationAwareBeanPostProcessorAndMergedBeanDefinitionPostProcessor
		implements MergedBeanDefinitionPostProcessor, InstantiationAwareBeanPostProcessor {


	@Override
	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
		System.out.println("["+beanName+"]实例化前k。。。");
		return null;
	}

	@Override
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		System.out.println("["+beanName+"]实例化后k。。。");
		return true;
	}

	@Override
	public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
		if(beanName.equals("user")) {
			beanDefinition.setInitMethodName("initFun1");  //把要执行的方法名字设置进去
			System.out.println("[" + beanName + "]postProcessMergedBeanDefinition()。。。");
		}

	}
}
